﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Program15_GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();

            //创建画笔对象
            //Pen pen = new Pen(Brushes.DarkRed);
            Pen pen = new Pen(Color.Crimson,4.0F);
            //线条风格
            //pen.DashStyle = DashStyle.Dot;
            float[] dashValues = { 2, 4, 6, 8 };
            pen.DashPattern = dashValues;

            //画直线，建立坐标
            Point p1 = new Point(30,50);
            Point p2 = new Point(300,50);

            //绘制直线
            g.DrawLine(pen,p1,p2);
        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Color.Crimson, 4.0F);
            //画出矩形
            g.DrawRectangle(pen,200,100,200,100);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Coral,6.0F);
            g.DrawEllipse(pen,90,90,200,100);
        }

        private void btnPie_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            SolidBrush bush = new SolidBrush(Color.Green);
            g.FillPie(bush,50,100,200,200,45,90);

            Color mycolor = Color.FromArgb(250,58,130,98);
            bush = new SolidBrush(mycolor);
            g.FillPie(bush, 50, 100, 200, 200,135, 90);

            //写字
            g.DrawString("音乐排名", new Font("宋体",20,FontStyle.Regular),Brushes.Black,new Point(30,50)) ;
        }

        private int i = 0;
        /// <summary>
        /// 当窗体绘图时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = ValidateCode.CreateVCode(4);

            //把图片读入内存
            MemoryStream ms = new MemoryStream();
            ms.Write(ValidateCode.CreateVCodePicture(label1.Text), 0, ValidateCode.CreateVCodePicture(label1.Text).Length);
            //显示图片的文件流格式
            pb_vCode.Image = Image.FromStream(ms);
        }
    }
}
